<extend name="Public:base" />
<block name="title">食堂档口管理</block>
<block name="content">
    <div class=" ace-save-state" id="breadcrumbs">
        <div class="page-header">
            <h1>食堂档口管理
                <small>
                    <i class="ace-icon fa fa-angle-double-right"></i><a href="{:U('Admin/Window/WindowList')}">食堂档口管理</a>
                </small>
                <small><i class="ace-icon fa fa-angle-double-right"></i>{$titleName}</small>
            </h1>
        </div>
        
        
        <!-- /.ace-settings-container -->
        <div class="page-content col-xs-11">
            
            <div class="row">
                <div class="col-xs-12">
                    <!-- PAGE CONTENT BEGINS -->
                    <div class="row">
                        <div class="col-xs-12">
                            <table id="simple-table" class="table  table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th class="detail-col center">档口名称</th>
                                    <th class="center">联系人</th>
                                    <th class="hidden-480 center">联系电话</th>
                                    <th class="center">所属食堂</th>
                                    <th>
                                        <button type="button" class="btn btn-sm btn-success" onclick="addWindow()">
                                            <span>添加档口</span>
                                        </button>
                                    
                                    
                                    </th>
                                </tr>
                                </thead>
                                
                                <tbody>
                                <?php foreach($windowList as $k=>$l){?>
                                <tr>
                                    <td class="center"><?php echo $l['window_name'];?></td>
                                    <td class="center"><?php echo $l['window_contact_name'];?></td>
                                    <td class="center"><?php echo $l['window_contact_phone'];?></td>
                                    <td class="hidden-480 center">
                                        <a href="/Admin/Window/windowList/?canteen_id=<?php echo $l['canteen_id'];?>"><?php echo $l['canteen_name'];?></a>
                                    </td>
                                    <td>
                                        <button type="button" class="btn btn-minier btn-primary" onclick="showOrder(<?php echo $l['member_id']?>)">
                                            <span>档口订单</span>
                                        </button>
                                        <button type="button" class="btn btn-minier btn-purple" onclick="editWindow(<?php echo $l['member_id']?>)">
                                            <span>修改信息</span>
                                        </button>
                                        <button type="button" class="btn btn-minier btn-danger" onclick="delWindow(<?php echo $l['member_id']?>)">
                                            <span>删除档口</span>
                                        </button>
                                    
                                    </td>
                                </tr>
                                <?php }?>
                                </tbody>
                            </table>
                        </div><!-- /.span -->
                    </div><!-- /.row -->
                    
                    
                    <!-- PAGE CONTENT ENDS -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div>
    </div>
    <div class="modal fade" id="bjy-add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times;</button>
                    <h4 class="modal-title" id="myModalLabel"> 添加档口</h4></div>
                <div class="modal-body">
                    <form id="bjy-form" class="form-inline" action="{:U('Admin/Window/addWindow')}" method="post">
                        <input type="hidden" name="pid" value="0">
                        <table class="table table-striped table-bordered table-hover table-condensed">
                            <tr>
                                <th width="20%">档口名称：</th>
                                <td><input class="input-medium" name="window_name" type="text" id="window_name"></td>
                                <td></td>
                            </tr>
                            <tr>
                                <th width="20%">所属食堂：</th>
                                <td>
                                    <select name="canteen_id" id="canteen_id">
                                        <?php foreach($canteenList as $canteen){?>
                                        <option value="<?php echo $canteen['canteen_id']?>"><?php echo $canteen['canteen_name']?></option>
                                        <?php }?>
                                    </select>
                                </td>
                                <td></td>
                            </tr>
                            <tr>
                                <th width="20%">联系人：</th>
                                <td>
                                    <input class="input-medium" type="text" name="window_contact_name" id="window_contact_name">
                                </td>
                                <td></td>
                            </tr>
                            <tr>
                                <th width="20%">联系电话：</th>
                                <td>
                                    <input class="input-medium" type="text" name="window_contact_phone" id="window_contact_phone">
                                </td>
                                <td></td>
                            </tr>
                            <tr>
                                <th width="20%">登陆账号：</th>
                                <td><input class="input-medium" type="text" name="username" id="username"></td>
                                <td>档口登陆账号</td>
                            </tr>
                            <tr>
                                <th width="20%">登陆密码：</th>
                                <td><input class="input-medium" type="text" name="password" id="password"></td>
                                <td></td>
                            <tr>
                                <td colspan="3" class="center">
                                    <input onclick="addSaveWindow()" style="width: 30%" class="btn btn-success" type="button" value="保存">
                                </td>
                            
                            </tr>
                        </table>
                    </form>
                </div>
            </div>
        </div>
    </div>
    
    <div class="modal fade" id="bjy-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times;</button>
                    <h4 class="modal-title" id="myModalLabel2"> 编辑档口</h4></div>
                <div class="modal-body">
                    <form id="bjy-edit-form" class="form-inline" action="{:U('Admin/Nav/add')}" method="post">
                        <input type="hidden" name="" id="member_id">
                        <table class="table table-striped table-bordered table-hover table-condensed">
                            <tr>
                                <th width="20%">档口名称：</th>
                                <td><input class="input-medium" type="text" id="window_name2"></td>
                                <td></td>
                            </tr>
                            <tr>
                                <th width="20%">联系人：</th>
                                <td><input class="input-medium" type="text" id="window_contact_name2"></td>
                                <td></td>
                            </tr>
                            <tr>
                                <th width="20%">联系电话：</th>
                                <td><input class="input-medium" type="text" id="window_contact_phone2"></td>
                                <td></td>
                            </tr>
                            <tr>
                                <th width="20%">登陆账号：</th>
                                <td><input class="input-medium" disabled type="text" id="username2"></td>
                                <td>档口登陆账号</td>
                            </tr>
                            <tr>
                                <th width="20%">登陆密码：</th>
                                <td><input class="input-medium" type="text" id="password2"></td>
                                <td>如无需修改，请留空</td>
                            </tr>
                            <tr>
                                <td colspan="3" class="center">
                                    <input onclick="saveEditWindow()" style="width: 30%" class="btn btn-success" type="button" value="保存">
                                </td>
                            
                            </tr>
                        </table>
                    </form>
                </div>
            </div>
        </div>
    </div>
    
    <script>
        function addSaveWindow() {
            var window_name = $("#window_name").val()
            var canteen_id = $("#canteen_id").val()
            var window_contact_name = $("#window_contact_name").val()
            var window_contact_phone = $("#window_contact_phone").val()
            var username = $("#username").val()
            var password = $("#password").val()
            if (!window_name) {
                alert("请输入档口名称")
                return false
            }
            if (!canteen_id) {
                alert("请选择所属食堂")
                return false
            }
            if (!window_contact_name) {
                alert("请输入联系人")
                return false
            }
            if (!window_contact_phone) {
                alert("请输入联系人号码")
                return false
            }
            if (!username) {
                alert("请输入登陆账号")
                return false
            }
            if (!password) {
                alert("请输入密码")
                return false
            }
            $("#bjy-form").submit()
        }

        function editWindow(member_id) {
            var data = AjaxGet('/Admin/Window/editWindow', {
                member_id: member_id
            })
            $("#window_name2").val(data.data.window_name)
            $("#window_contact_name2").val(data.data.window_contact_name)
            $("#window_contact_phone2").val(data.data.window_contact_phone)
            $("#username2").val(data.data.username)
            $("#password2").val(null)
            $("#member_id").val(member_id)
            $('#bjy-edit').modal('show');

        }

        function saveEditWindow() {
            var member_id = $("#member_id").val()

            var window_name = $("#window_name2").val()
            var window_contact_name = $("#window_contact_name2").val()
            var window_contact_phone = $("#window_contact_phone2").val()
            var password = $("#password2").val()
            var member_id = $("#member_id").val()

            if (!window_name) {
                alert("请输入档口名称")
                return false
            }
            if (!window_contact_name) {
                alert("请输入档口联系人")
                return false
            }
            if (!window_contact_phone) {
                alert("请输入饭堂联系电话")
                return false
            }
            var data = AjaxPost('/Admin/Window/editWindow', {
                member_id: member_id,
                window_name: window_name,
                window_contact_name: window_contact_name,
                window_contact_phone: window_contact_phone,
                password: password
            })
            if (data.status == true) {
                alert("保存成功")
                window.location.reload()
            } else {
                alert("操作失败，请联系管理员")
            }
        }

        function manageCanteen(canteen_id) {
            alert(canteen_id)
        }

        function delWindow(member_id) {
            var flag = confirm("删除档口后，该档口不能继续登陆操作，是否继续？")
            if (flag == true) {
                var data = AjaxPost('/Admin/Window/delWindow', {
                    member_id: member_id
                })
                if (data.status == true) {
                    alert("删除成功")
                    window.location.reload()
                } else {
                    alert("操作失败，请联系管理员")
                }

            }

        }

        function addWindow() {
            $('#bjy-add').modal('show');
        }

        function saveWindow() {
            var canteen_name = $("#canteen_name").val()
            var canteen_contact_name = $("#canteen_contact_name").val()
            var canteen_contact_phone = $("#canteen_contact_phone").val()
            if (!canteen_name) {
                alert("请填写正确的食堂名称")
                return false
            }
            if (!canteen_contact_name) {
                alert("请填写食堂联系人")
                return false
            }
            if (!canteen_contact_phone) {
                alert("请填写食堂联系电话")
                return false
            }
            var data = AjaxPost("/Admin/Window/addCanteen", {
                canteen_name: canteen_name,
                canteen_contact_name: canteen_contact_name,
                canteen_contact_phone: canteen_contact_phone
            })
            if (data.status == true) {
                alert('添加成功')
                window.location.reload()
            } else {
                alert(data.message)
            }


        }

        function showOrder(member_id) {
            window.location.href = "{:U('Admin/Order/WindowOrder')}" + "/member_id/" + member_id
        }
    </script>
</block>
<block name="js"></block>
